package com.dubbo.controller;

import com.dubbo.common.ResponseUtil;
import com.dubbo.common.exception.UserExpiredException;
import com.dubbo.common.redis.RedisDao;
import com.dubbo.common.result.ResultInfo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * 用户注销处理器
 * @author chenwei
 * @date 2018年3月26日 上午11:14:39
 */
@Controller
public class LogoutController {
	@Value("${user.prefixkey.redis}")
	private String technicianTicket;
	
//	@Autowired
//	private TechnicianMapper technicianMapper;
	
//	@Value("${cart.key.cookie}")
//	private String userCart;
	@Autowired
	private RedisDao redisDao;
	
	/**
	 * 退出登录
	 * 
	 * @author chenwei
	 * @date 2018年3月26日 上午11:15:59
	 * @return
	 * @throws UserExpiredException 
	 */
	@PostMapping("/logout.wx")
	@ResponseBody
	public Map<String,Object> logout(HttpServletRequest request) throws UserExpiredException {
		String cookieValue = request.getHeader(ResultInfo.USERTOKEN);
		if(!StringUtils.isNotBlank(cookieValue)) {
			return ResponseUtil.ajaxCheckSuccess("退出成功!");
		}
		redisDao.delete(cookieValue);
		return ResponseUtil.ajaxCheckSuccess("退出成功!");
	}
	
	
}
